package com.daumcorp.searchdata.web;

import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.daumcorp.searchdata.domain.Book;
import com.daumcorp.searchdata.service.BookService;

@Controller
@RequestMapping("/bookjson")
public class BookJsonController {
	@Autowired
	private BookService bookService;

	@RequestMapping
	@ResponseBody
	public List<Book> readAllBook() {
		return bookService.findAllBook();
	}

	@RequestMapping(value = "/register", method = RequestMethod.POST)
	@ResponseBody
	public Book registerBook(@RequestBody @Valid Book book) {
		bookService.saveBook(book);
		return book;
	}

	@RequestMapping("/{isbn}")
	@ResponseBody
	public Book action(@PathVariable String isbn) {
		return bookService.findBookByIsbn(isbn);
	}
}